import numpy as np


# 归一化
class Divide(object):
    def __init__(self, n=500):
        """
        归一化方法为 x/n
        :param n: 分母
        """
        self.n = n

    def __call__(self, x):
        if isinstance(x, list):
            x = np.array(x)
        assert isinstance(x, np.ndarray)
        return x / self.n


class ZScore(object):
    def __init__(self):
        """
        归一化方法：(x-min) / (max-min) 到[0,1]之间
        """
        self.max = 0
        self.min = 0

    def renorm(self, x):
        if isinstance(x, list):
            x = np.array(x)
        assert isinstance(x, np.ndarray)
        return x*(self.max-self.min)+self.min

    def __call__(self, x):
        if isinstance(x, list):
            x = np.array(x)
        assert isinstance(x, np.ndarray)
        self.min = np.min(x)
        self.max = np.max(x)
        range = self.max - self.min
        return (x - self.min) / range


if __name__ == "__main__":
    D = Divide(200)
    MM = Min_Max_scale()
    x = np.random.randint(0, 200, (5, 10))
    print(x)
    print(D(x))
    print(MM(x))
